﻿/* ==============================================================================
 * 功能描述：UIAtlas  
 * 
 * 创 建 者：郑镇泉
 * 
 * 创建日期：2016/4/7 13:31:33
 * ==============================================================================*/
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;

public class UIAtlas : ScriptableObject
{
    public Texture2D mainTexture;

    public List<Sprite> spriteLists = new List<Sprite>();

    /// <summary>
    /// 根据Y名?字?获?取?sprite
    /// </summary>
    /// <param name="spriteName"> 名?称?</param>
    /// <returns></returns>
    public Sprite GetSprite(string spriteName)
    {
        return spriteLists.Find((Sprite s) => { return s.name == spriteName; });
    }

    /// <summary>
    /// 设置?image的?Sprite
    /// </summary>
    /// <param name="im"> Image</param>
    /// <param name="spriteName"> Sprite名?称?</param>
    public void SetSprite(ref Image im, string spriteName, bool isSetNative = true)
    {
        if (im == null)
        {
            return;
        }

        Sprite sp = GetSprite(spriteName);
        if (sp != null)
        {
            im.sprite = sp;
            if (isSetNative)
            {
                im.SetNativeSize();
            }
        }
        else
        {
            Debug.LogError(string.Format("你?要a设置?的?spriteName：o{0} 没?有D在这a个?图?集中D " + spriteName));
        }
    }

}

